#!/bin/sh
#
# This is the script for generating files for a specific Dalton test job.
#
# For the .check file ksh or bash is preferred, otherwise use sh
# (and hope it is not the old Bourne shell, which will not work)
#
if [ -x /bin/ksh ]; then
   CHECK_SHELL='#!/bin/ksh'
elif [ -x /bin/bash ]; then
   CHECK_SHELL='#!/bin/bash'
else
   CHECK_SHELL='#!/bin/sh'
fi


#######################################################################
#  TEST DESCRIPTION
#######################################################################
cat > rsp_propave.info <<'%EOF%'
   rsp_propave
   -----------
   Molecule:         LiH
   Wave Function:    SCF / STO-3G
   Test Purpose:     Check that AVEPRP in response works properly
%EOF%

#######################################################################
#  MOLECULE INPUT
#######################################################################
cat > rsp_propave.mol <<'%EOF%'
BASIS
STO-3G
Calculation to verify that AVEPRP in response works properly

    2    2  X  Y
        3.    1
Li   0.000000   0.000000    0.7581192283
        1.    1
H    0.000000   0.000000    -2.2743576849
%EOF%

#######################################################################
#  DALTON INPUT
#######################################################################
cat > rsp_propave.dal <<'%EOF%'
**DALTON INPUT
.RUN RESPONSE
**INTEGRALS
.DIPLEN
.DIPVEL
**WAVE FUNCTION
.HF
**RESPONSE
.S0MIX
.PROPAVE
ZDIPLEN
**END OF DALTON INPUT
%EOF%
#######################################################################



#######################################################################

#######################################################################
#  CHECK SCRIPT
#######################################################################
echo $CHECK_SHELL >rsp_propave.check
cat >>rsp_propave.check <<'%EOF%'
#!/bin/bash
log=$1

if [ `uname` = Linux ]; then
   GREP="egrep -a"
else
   GREP="egrep"
fi

# Integral setup
CRIT1=`$GREP "Calculation of one\- and two\-electron Hamiltonian integrals\." $log | wc -l`
CRIT1b=`$GREP "Calculation of one\-electron Hamiltonian integrals\." $log | wc -l`
CRIT2=`$GREP "The following one\-electron property integrals are calculated" $log | wc -l`
CRIT3=`$GREP "\- overlap integrals" $log | wc -l`
CRIT4=`$GREP "\- dipole length integrals" $log | wc -l`
CRIT5=`$GREP "two-electron integrals are transformed to P-supermatrix elements" $log | wc -l`
CRIT5b=`$GREP "Fock matrices are calculated directly and in parallel without use of integrals on disk" $log |wc -l`
TEST[1]=`expr	$CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4 \+ $CRIT5 \+ $CRIT1b \+ $CRIT5b`
CTRL[1]=5
ERROR[1]="INTEGRAL CALCULATION NOT SET UP CORRECTLY"

# Basis set
CRIT1=`$GREP "Basis set used is \"STO\-3G\" from the basis set library\." $log | wc -l`
CRIT2=`$GREP "Li * 1 * 3\.0000 * 15 * 5 * \[6s3p\|2s1p\]" $log | wc -l`
CRIT3=`$GREP "H * 1 * 1\.0000 * 3 * 1 * \[3s\|1s\]" $log | wc -l`
CRIT4=`$GREP "total\: * 2 * 4\.0000 * 18 * 6" $log | wc -l`
TEST[2]=`expr	$CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4`
CTRL[2]=4
ERROR[2]="BASIS SET NOT READ CORRECTLY"

# Geometry
CRIT1=`$GREP "Total number of coordinates\: * 6" $log | wc -l`
CRIT2=`$GREP "1 * x * (0| )\.0000000000" $log | wc -l`
CRIT3=`$GREP "2 * y * (0| )\.0000000000" $log | wc -l`
CRIT4=`$GREP "3 * z * (0| )\.7581192283" $log | wc -l`
CRIT5=`$GREP "4 * x * (0| )\.0000000000" $log | wc -l`
CRIT6=`$GREP "5 * y * (0| )\.0000000000" $log | wc -l`
CRIT7=`$GREP "6 * z * \-2\.2743576849" $log | wc -l`
TEST[3]=`expr	$CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4 \+ $CRIT5 \+ $CRIT6 \+ \
		$CRIT7`
CTRL[3]=7
ERROR[3]="GEOMETRY NOT READ CORRECTLY"

# Symmetry
CRIT1=`$GREP "Number of coordinates in each symmetry\: * 2 * 2 * 2 * 0" $log | wc -l`
CRIT2=`$GREP "Number of orbitals in each symmetry\: * 4 * 1 * 1 * 0" $log | wc -l`
TEST[4]=`expr	$CRIT1 \+ $CRIT2`
CTRL[4]=2
ERROR[4]="SYMMETRY NOT CORRECT"

# Energy
CRIT1=`$GREP "Final * HF energy\: * \-7\.86170731521[0-9]" $log | wc -l`
TEST[5]=`expr	$CRIT1`
CTRL[5]=1
ERROR[5]="ENERGY NOT CORRECT"

# Average value
CRIT1=`$GREP "Calculation of electronic one\-electron expectation values" $log | wc -l`
CRIT2=`$GREP "ZDIPLEN * inactive part\: * \-1\.9120[45]..." $log | wc -l`
CRIT3=`$GREP "ZDIPLEN * active part * \: * 0*\.00000000" $log | wc -l`
CRIT4=`$GREP "ZDIPLEN * total * \: * \-1\.9120[45]..." $log | wc -l`
TEST[6]=`expr	$CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4`
CTRL[6]=4
ERROR[6]="AVERAGE VALUE NOT CORRECT"

PASSED=1
for i in 1 2 3 4 5 6
do
   if [ ${TEST[i]} -ne ${CTRL[i]} ]; then
     echo "${ERROR[i]} ( test = ${TEST[i]}; control = ${CTRL[i]} )"
     PASSED=0
   fi
done

if [ $PASSED -eq 1 ]
then
  echo TEST ENDED PROPERLY
  exit 0
else
  echo THERE IS A PROBLEM
  exit 1
fi

%EOF%
#######################################################################
